package com.sugou.model.commons;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;

import com.sugou.dao.enums.RegionLevel;
import com.sugou.dao.enums.TF;
import com.sugou.model.core.base.LongIdEntity;

/** 
 * 用户所选地区
 * 
 * @author 胡三兵 E-mail:bz_hsb@126.com 
 * @version 创建时间：2012-10-28 下午1:54:45
 */
@Entity(name="Area")
@Table(name = "GW_AREA")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Area extends LongIdEntity {
	
	private static final long serialVersionUID = 7571720111707086829L;

	//地区代码
	@Column(nullable = false)
	private String code;
	
	//地区名字
	@Column(nullable = false)
	private String name;	
		
	// 是否是叶子
	@Column(nullable = false, columnDefinition = "tinyint(4) default 0")
	@Type(type = "org.hibernate.type.EnumType", parameters = {
	@Parameter(name = "enumClass", value = "com.ustudy.products.enums.TF"),
	@Parameter(name = "type", value = "-6"/* TINYINT */) })
	private TF isLeaf = TF.NO;		

	// 排序号
	@Column(nullable = false)
	private Integer sortNum;

	// 父ID
	@ManyToOne(cascade={CascadeType.ALL},fetch=FetchType.LAZY)
	@JoinColumn(name="PID",nullable=true)
	private Area pid;

	@OneToMany(cascade={CascadeType.ALL},mappedBy="pid",fetch=FetchType.LAZY)
	private List<Area> children;
	/**
	 * 地区级别
	 */
	@Column(nullable = false, columnDefinition = "tinyint(4) default 3")
	@Type(type = "org.hibernate.type.EnumType", parameters = {
	@Parameter(name = "enumClass", value = "com.ustudy.products.enums.RegionLevel"),
	@Parameter(name = "type", value = "-6"/* TINYINT */) })
	private RegionLevel level=RegionLevel.REGION;
	public RegionLevel getLevel() {
		return level;
	}

	public void setLevel(RegionLevel level) {
		this.level = level;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}	

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public TF getIsLeaf() {
		return isLeaf;
	}

	public void setIsLeaf(TF isLeaf) {
		this.isLeaf = isLeaf;
	}

	public void setSortNum(Integer sortNum) {
		this.sortNum = sortNum;
	}

	public Integer getSortNum() {
		return sortNum;
	}

	public Area getPid() {
		return pid;
	}

	public void setPid(Area pid) {
		this.pid = pid;
	}

	public List<Area> getChildren() {
		return children;
	}

	public void setChildren(List<Area> children) {
		this.children = children;
	}
}
